using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace LMHTX.Modules.DIRECTORY.COOPERATIVE.Components
{
    public partial class Cooperative
    {
        #region Private members.

        protected int _ID;
        protected Guid _ModuleID = Guid.Empty;
        protected int _AreaID;
        protected int _CareerID;
        protected int _TypeID;
        protected string _Title = string.Empty;
        protected int _ChairmanID;
        protected int _ChiefAccountantID;
        protected int _ControllerID;
        protected int _ViceChairmanID;
        protected string _Address = string.Empty;
        protected string _Email = string.Empty;
        protected string _Fax = string.Empty;
        protected string _Phone = string.Empty;
        protected string _Website = string.Empty;
        protected int _EstablishedYear;
        protected string _LicenseNumber = string.Empty;
        protected string _OrganizationDescription = string.Empty;
        protected bool _HasPartyOrganization;
        protected bool _HasTheCommunistYouthLeague;
        protected bool _HasTradeUnion;
        protected bool _HasWomanUnion;
        protected bool _HasInlandMarket;
        protected bool _HasOutlandMarket;
        protected string _MarketDescription = string.Empty;
        protected string _ProductDescription = string.Empty;
        protected string _Description = string.Empty;
        protected DateTime _CreatedDate = new DateTime(1753, 1, 1);
        protected string _CreatedBy = string.Empty;
        protected DateTime _ApprovedDate = new DateTime(1753, 1, 1);
        protected string _ApprovedBy = string.Empty;

        #endregion

        //---------------------------------------------------------------------------------------------

        #region Properties.

        public int ID
        {
            set { this._ID = value; }
            get { return this._ID; }
        }

        public Guid ModuleID
        {
            set { this._ModuleID = value; }
            get { return this._ModuleID; }
        }

        public int AreaID
        {
            set { this._AreaID = value; }
            get { return this._AreaID; }
        }

        public int CareerID
        {
            set { this._CareerID = value; }
            get { return this._CareerID; }
        }

        public int TypeID
        {
            set { this._TypeID = value; }
            get { return this._TypeID; }
        }

        public string Title
        {
            set { this._Title = value; }
            get { return this._Title; }
        }

        public int ChairmanID
        {
            set { this._ChairmanID = value; }
            get { return this._ChairmanID; }
        }

        public int ChiefAccountantID
        {
            set { this._ChiefAccountantID = value; }
            get { return this._ChiefAccountantID; }
        }

        public int ControllerID
        {
            set { this._ControllerID = value; }
            get { return this._ControllerID; }
        }

        public int ViceChairmanID
        {
            set { this._ViceChairmanID = value; }
            get { return this._ViceChairmanID; }
        }

        public string Address
        {
            set { this._Address = value; }
            get { return this._Address; }
        }

        public string Email
        {
            set { this._Email = value; }
            get { return this._Email; }
        }

        public string Fax
        {
            set { this._Fax = value; }
            get { return this._Fax; }
        }

        public string Phone
        {
            set { this._Phone = value; }
            get { return this._Phone; }
        }

        public string Website
        {
            set { this._Website = value; }
            get { return this._Website; }
        }

        public int EstablishedYear
        {
            set { this._EstablishedYear = value; }
            get { return this._EstablishedYear; }
        }

        public string LicenseNumber
        {
            set { this._LicenseNumber = value; }
            get { return this._LicenseNumber; }
        }

        public string OrganizationDescription
        {
            set { this._OrganizationDescription = value; }
            get { return this._OrganizationDescription; }
        }

        public bool HasPartyOrganization
        {
            set { this._HasPartyOrganization = value; }
            get { return this._HasPartyOrganization; }
        }

        public bool HasTheCommunistYouthLeague
        {
            set { this._HasTheCommunistYouthLeague = value; }
            get { return this._HasTheCommunistYouthLeague; }
        }

        public bool HasTradeUnion
        {
            set { this._HasTradeUnion = value; }
            get { return this._HasTradeUnion; }
        }

        public bool HasWomanUnion
        {
            set { this._HasWomanUnion = value; }
            get { return this._HasWomanUnion; }
        }

        public bool HasInlandMarket
        {
            set { this._HasInlandMarket = value; }
            get { return this._HasInlandMarket; }
        }

        public bool HasOutlandMarket
        {
            set { this._HasOutlandMarket = value; }
            get { return this._HasOutlandMarket; }
        }

        public string MarketDescription
        {
            set { this._MarketDescription = value; }
            get { return this._MarketDescription; }
        }

        public string ProductDescription
        {
            set { this._ProductDescription = value; }
            get { return this._ProductDescription; }
        }

        public string Description
        {
            set { this._Description = value; }
            get { return this._Description; }
        }

        public DateTime CreatedDate
        {
            set { this._CreatedDate = value; }
            get { return this._CreatedDate; }
        }

        public string CreatedBy
        {
            set { this._CreatedBy = value; }
            get { return this._CreatedBy; }
        }

        public DateTime ApprovedDate
        {
            set { this._ApprovedDate = value; }
            get { return this._ApprovedDate; }
        }

        public string ApprovedBy
        {
            set { this._ApprovedBy = value; }
            get { return this._ApprovedBy; }
        }


        #endregion

        //---------------------------------------------------------------------------------------------

        #region Select methods.

        public static Cooperative Load(int id)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_Load]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, id);
            Cooperative entity = null;
            IDataReader reader = db.ExecuteReader(dbCommand);
            if (reader.Read())
            {
                entity = new Cooperative();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("AreaID"))) entity.AreaID = reader.GetInt32(reader.GetOrdinal("AreaID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CareerID"))) entity.CareerID = reader.GetInt32(reader.GetOrdinal("CareerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("TypeID"))) entity.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChairmanID"))) entity.ChairmanID = reader.GetInt32(reader.GetOrdinal("ChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChiefAccountantID"))) entity.ChiefAccountantID = reader.GetInt32(reader.GetOrdinal("ChiefAccountantID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ControllerID"))) entity.ControllerID = reader.GetInt32(reader.GetOrdinal("ControllerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ViceChairmanID"))) entity.ViceChairmanID = reader.GetInt32(reader.GetOrdinal("ViceChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) entity.Address = reader.GetString(reader.GetOrdinal("Address"));
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) entity.Email = reader.GetString(reader.GetOrdinal("Email"));
                if (!reader.IsDBNull(reader.GetOrdinal("Fax"))) entity.Fax = reader.GetString(reader.GetOrdinal("Fax"));
                if (!reader.IsDBNull(reader.GetOrdinal("Phone"))) entity.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                if (!reader.IsDBNull(reader.GetOrdinal("Website"))) entity.Website = reader.GetString(reader.GetOrdinal("Website"));
                if (!reader.IsDBNull(reader.GetOrdinal("EstablishedYear"))) entity.EstablishedYear = reader.GetInt32(reader.GetOrdinal("EstablishedYear"));
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNumber"))) entity.LicenseNumber = reader.GetString(reader.GetOrdinal("LicenseNumber"));
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationDescription"))) entity.OrganizationDescription = reader.GetString(reader.GetOrdinal("OrganizationDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasPartyOrganization"))) entity.HasPartyOrganization = reader.GetBoolean(reader.GetOrdinal("HasPartyOrganization"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTheCommunistYouthLeague"))) entity.HasTheCommunistYouthLeague = reader.GetBoolean(reader.GetOrdinal("HasTheCommunistYouthLeague"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTradeUnion"))) entity.HasTradeUnion = reader.GetBoolean(reader.GetOrdinal("HasTradeUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasWomanUnion"))) entity.HasWomanUnion = reader.GetBoolean(reader.GetOrdinal("HasWomanUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasInlandMarket"))) entity.HasInlandMarket = reader.GetBoolean(reader.GetOrdinal("HasInlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasOutlandMarket"))) entity.HasOutlandMarket = reader.GetBoolean(reader.GetOrdinal("HasOutlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("MarketDescription"))) entity.MarketDescription = reader.GetString(reader.GetOrdinal("MarketDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("ProductDescription"))) entity.ProductDescription = reader.GetString(reader.GetOrdinal("ProductDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
            }
            reader.Close();
            return entity;
        }

        //---------------------------------------------------------------------------------------------
        public static List<Cooperative> SelectCollectionAll(Guid moduleID)
        {
            List<Cooperative> collection = new List<Cooperative>();
            SqlDataReader reader = (SqlDataReader)SelectReaderAll(moduleID);
            while (reader.Read())
            {
                Cooperative entity = new Cooperative();

                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("AreaID"))) entity.AreaID = reader.GetInt32(reader.GetOrdinal("AreaID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CareerID"))) entity.CareerID = reader.GetInt32(reader.GetOrdinal("CareerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("TypeID"))) entity.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChairmanID"))) entity.ChairmanID = reader.GetInt32(reader.GetOrdinal("ChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChiefAccountantID"))) entity.ChiefAccountantID = reader.GetInt32(reader.GetOrdinal("ChiefAccountantID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ControllerID"))) entity.ControllerID = reader.GetInt32(reader.GetOrdinal("ControllerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ViceChairmanID"))) entity.ViceChairmanID = reader.GetInt32(reader.GetOrdinal("ViceChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) entity.Address = reader.GetString(reader.GetOrdinal("Address"));
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) entity.Email = reader.GetString(reader.GetOrdinal("Email"));
                if (!reader.IsDBNull(reader.GetOrdinal("Fax"))) entity.Fax = reader.GetString(reader.GetOrdinal("Fax"));
                if (!reader.IsDBNull(reader.GetOrdinal("Phone"))) entity.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                if (!reader.IsDBNull(reader.GetOrdinal("Website"))) entity.Website = reader.GetString(reader.GetOrdinal("Website"));
                if (!reader.IsDBNull(reader.GetOrdinal("EstablishedYear"))) entity.EstablishedYear = reader.GetInt32(reader.GetOrdinal("EstablishedYear"));
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNumber"))) entity.LicenseNumber = reader.GetString(reader.GetOrdinal("LicenseNumber"));
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationDescription"))) entity.OrganizationDescription = reader.GetString(reader.GetOrdinal("OrganizationDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasPartyOrganization"))) entity.HasPartyOrganization = reader.GetBoolean(reader.GetOrdinal("HasPartyOrganization"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTheCommunistYouthLeague"))) entity.HasTheCommunistYouthLeague = reader.GetBoolean(reader.GetOrdinal("HasTheCommunistYouthLeague"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTradeUnion"))) entity.HasTradeUnion = reader.GetBoolean(reader.GetOrdinal("HasTradeUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasWomanUnion"))) entity.HasWomanUnion = reader.GetBoolean(reader.GetOrdinal("HasWomanUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasInlandMarket"))) entity.HasInlandMarket = reader.GetBoolean(reader.GetOrdinal("HasInlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasOutlandMarket"))) entity.HasOutlandMarket = reader.GetBoolean(reader.GetOrdinal("HasOutlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("MarketDescription"))) entity.MarketDescription = reader.GetString(reader.GetOrdinal("MarketDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("ProductDescription"))) entity.ProductDescription = reader.GetString(reader.GetOrdinal("ProductDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
                collection.Add(entity);
            }

            reader.Close();
            return collection;
        }

        //---------------------------------------------------------------------------------------------

        public static List<Cooperative> SelectCollectionDynamic(string whereCondition, string orderByExpression)
        {
            List<Cooperative> collection = new List<Cooperative>();

            SqlDataReader reader = (SqlDataReader)SelectReaderDynamic(whereCondition, orderByExpression);
            while (reader.Read())
            {
                Cooperative entity = new Cooperative();

                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("AreaID"))) entity.AreaID = reader.GetInt32(reader.GetOrdinal("AreaID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CareerID"))) entity.CareerID = reader.GetInt32(reader.GetOrdinal("CareerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("TypeID"))) entity.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChairmanID"))) entity.ChairmanID = reader.GetInt32(reader.GetOrdinal("ChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChiefAccountantID"))) entity.ChiefAccountantID = reader.GetInt32(reader.GetOrdinal("ChiefAccountantID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ControllerID"))) entity.ControllerID = reader.GetInt32(reader.GetOrdinal("ControllerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ViceChairmanID"))) entity.ViceChairmanID = reader.GetInt32(reader.GetOrdinal("ViceChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) entity.Address = reader.GetString(reader.GetOrdinal("Address"));
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) entity.Email = reader.GetString(reader.GetOrdinal("Email"));
                if (!reader.IsDBNull(reader.GetOrdinal("Fax"))) entity.Fax = reader.GetString(reader.GetOrdinal("Fax"));
                if (!reader.IsDBNull(reader.GetOrdinal("Phone"))) entity.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                if (!reader.IsDBNull(reader.GetOrdinal("Website"))) entity.Website = reader.GetString(reader.GetOrdinal("Website"));
                if (!reader.IsDBNull(reader.GetOrdinal("EstablishedYear"))) entity.EstablishedYear = reader.GetInt32(reader.GetOrdinal("EstablishedYear"));
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNumber"))) entity.LicenseNumber = reader.GetString(reader.GetOrdinal("LicenseNumber"));
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationDescription"))) entity.OrganizationDescription = reader.GetString(reader.GetOrdinal("OrganizationDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasPartyOrganization"))) entity.HasPartyOrganization = reader.GetBoolean(reader.GetOrdinal("HasPartyOrganization"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTheCommunistYouthLeague"))) entity.HasTheCommunistYouthLeague = reader.GetBoolean(reader.GetOrdinal("HasTheCommunistYouthLeague"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTradeUnion"))) entity.HasTradeUnion = reader.GetBoolean(reader.GetOrdinal("HasTradeUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasWomanUnion"))) entity.HasWomanUnion = reader.GetBoolean(reader.GetOrdinal("HasWomanUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasInlandMarket"))) entity.HasInlandMarket = reader.GetBoolean(reader.GetOrdinal("HasInlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasOutlandMarket"))) entity.HasOutlandMarket = reader.GetBoolean(reader.GetOrdinal("HasOutlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("MarketDescription"))) entity.MarketDescription = reader.GetString(reader.GetOrdinal("MarketDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("ProductDescription"))) entity.ProductDescription = reader.GetString(reader.GetOrdinal("ProductDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
                collection.Add(entity);
            }

            reader.Close();
            return collection;
        }

        //---------------------------------------------------------------------------------------------

        // Select by foreign key return collection		
        public static IList<Cooperative> SelectCollectionBy_AreaID(int areaID)
        {
            List<Cooperative> collection = new List<Cooperative>();
            SqlDataReader reader = (SqlDataReader)SelectReaderBy_AreaID(areaID);
            while (reader.Read())
            {
                Cooperative entity = new Cooperative();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("AreaID"))) entity.AreaID = reader.GetInt32(reader.GetOrdinal("AreaID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CareerID"))) entity.CareerID = reader.GetInt32(reader.GetOrdinal("CareerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("TypeID"))) entity.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChairmanID"))) entity.ChairmanID = reader.GetInt32(reader.GetOrdinal("ChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChiefAccountantID"))) entity.ChiefAccountantID = reader.GetInt32(reader.GetOrdinal("ChiefAccountantID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ControllerID"))) entity.ControllerID = reader.GetInt32(reader.GetOrdinal("ControllerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ViceChairmanID"))) entity.ViceChairmanID = reader.GetInt32(reader.GetOrdinal("ViceChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) entity.Address = reader.GetString(reader.GetOrdinal("Address"));
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) entity.Email = reader.GetString(reader.GetOrdinal("Email"));
                if (!reader.IsDBNull(reader.GetOrdinal("Fax"))) entity.Fax = reader.GetString(reader.GetOrdinal("Fax"));
                if (!reader.IsDBNull(reader.GetOrdinal("Phone"))) entity.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                if (!reader.IsDBNull(reader.GetOrdinal("Website"))) entity.Website = reader.GetString(reader.GetOrdinal("Website"));
                if (!reader.IsDBNull(reader.GetOrdinal("EstablishedYear"))) entity.EstablishedYear = reader.GetInt32(reader.GetOrdinal("EstablishedYear"));
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNumber"))) entity.LicenseNumber = reader.GetString(reader.GetOrdinal("LicenseNumber"));
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationDescription"))) entity.OrganizationDescription = reader.GetString(reader.GetOrdinal("OrganizationDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasPartyOrganization"))) entity.HasPartyOrganization = reader.GetBoolean(reader.GetOrdinal("HasPartyOrganization"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTheCommunistYouthLeague"))) entity.HasTheCommunistYouthLeague = reader.GetBoolean(reader.GetOrdinal("HasTheCommunistYouthLeague"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTradeUnion"))) entity.HasTradeUnion = reader.GetBoolean(reader.GetOrdinal("HasTradeUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasWomanUnion"))) entity.HasWomanUnion = reader.GetBoolean(reader.GetOrdinal("HasWomanUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasInlandMarket"))) entity.HasInlandMarket = reader.GetBoolean(reader.GetOrdinal("HasInlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasOutlandMarket"))) entity.HasOutlandMarket = reader.GetBoolean(reader.GetOrdinal("HasOutlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("MarketDescription"))) entity.MarketDescription = reader.GetString(reader.GetOrdinal("MarketDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("ProductDescription"))) entity.ProductDescription = reader.GetString(reader.GetOrdinal("ProductDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
                collection.Add(entity);
            }
            reader.Close();
            return collection;
        }
        //---------------------------------------------------------------------------------------------
        public static IList<Cooperative> SelectCollectionBy_CareerID(int careerID)
        {
            List<Cooperative> collection = new List<Cooperative>();
            SqlDataReader reader = (SqlDataReader)SelectReaderBy_CareerID(careerID);
            while (reader.Read())
            {
                Cooperative entity = new Cooperative();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("AreaID"))) entity.AreaID = reader.GetInt32(reader.GetOrdinal("AreaID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CareerID"))) entity.CareerID = reader.GetInt32(reader.GetOrdinal("CareerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("TypeID"))) entity.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChairmanID"))) entity.ChairmanID = reader.GetInt32(reader.GetOrdinal("ChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChiefAccountantID"))) entity.ChiefAccountantID = reader.GetInt32(reader.GetOrdinal("ChiefAccountantID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ControllerID"))) entity.ControllerID = reader.GetInt32(reader.GetOrdinal("ControllerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ViceChairmanID"))) entity.ViceChairmanID = reader.GetInt32(reader.GetOrdinal("ViceChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) entity.Address = reader.GetString(reader.GetOrdinal("Address"));
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) entity.Email = reader.GetString(reader.GetOrdinal("Email"));
                if (!reader.IsDBNull(reader.GetOrdinal("Fax"))) entity.Fax = reader.GetString(reader.GetOrdinal("Fax"));
                if (!reader.IsDBNull(reader.GetOrdinal("Phone"))) entity.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                if (!reader.IsDBNull(reader.GetOrdinal("Website"))) entity.Website = reader.GetString(reader.GetOrdinal("Website"));
                if (!reader.IsDBNull(reader.GetOrdinal("EstablishedYear"))) entity.EstablishedYear = reader.GetInt32(reader.GetOrdinal("EstablishedYear"));
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNumber"))) entity.LicenseNumber = reader.GetString(reader.GetOrdinal("LicenseNumber"));
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationDescription"))) entity.OrganizationDescription = reader.GetString(reader.GetOrdinal("OrganizationDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasPartyOrganization"))) entity.HasPartyOrganization = reader.GetBoolean(reader.GetOrdinal("HasPartyOrganization"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTheCommunistYouthLeague"))) entity.HasTheCommunistYouthLeague = reader.GetBoolean(reader.GetOrdinal("HasTheCommunistYouthLeague"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTradeUnion"))) entity.HasTradeUnion = reader.GetBoolean(reader.GetOrdinal("HasTradeUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasWomanUnion"))) entity.HasWomanUnion = reader.GetBoolean(reader.GetOrdinal("HasWomanUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasInlandMarket"))) entity.HasInlandMarket = reader.GetBoolean(reader.GetOrdinal("HasInlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasOutlandMarket"))) entity.HasOutlandMarket = reader.GetBoolean(reader.GetOrdinal("HasOutlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("MarketDescription"))) entity.MarketDescription = reader.GetString(reader.GetOrdinal("MarketDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("ProductDescription"))) entity.ProductDescription = reader.GetString(reader.GetOrdinal("ProductDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
                collection.Add(entity);
            }
            reader.Close();
            return collection;
        }
        //---------------------------------------------------------------------------------------------
        public static IList<Cooperative> SelectCollectionBy_ChairmanID(int chairmanID)
        {
            List<Cooperative> collection = new List<Cooperative>();
            SqlDataReader reader = (SqlDataReader)SelectReaderBy_ChairmanID(chairmanID);
            while (reader.Read())
            {
                Cooperative entity = new Cooperative();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("AreaID"))) entity.AreaID = reader.GetInt32(reader.GetOrdinal("AreaID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CareerID"))) entity.CareerID = reader.GetInt32(reader.GetOrdinal("CareerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("TypeID"))) entity.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChairmanID"))) entity.ChairmanID = reader.GetInt32(reader.GetOrdinal("ChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChiefAccountantID"))) entity.ChiefAccountantID = reader.GetInt32(reader.GetOrdinal("ChiefAccountantID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ControllerID"))) entity.ControllerID = reader.GetInt32(reader.GetOrdinal("ControllerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ViceChairmanID"))) entity.ViceChairmanID = reader.GetInt32(reader.GetOrdinal("ViceChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) entity.Address = reader.GetString(reader.GetOrdinal("Address"));
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) entity.Email = reader.GetString(reader.GetOrdinal("Email"));
                if (!reader.IsDBNull(reader.GetOrdinal("Fax"))) entity.Fax = reader.GetString(reader.GetOrdinal("Fax"));
                if (!reader.IsDBNull(reader.GetOrdinal("Phone"))) entity.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                if (!reader.IsDBNull(reader.GetOrdinal("Website"))) entity.Website = reader.GetString(reader.GetOrdinal("Website"));
                if (!reader.IsDBNull(reader.GetOrdinal("EstablishedYear"))) entity.EstablishedYear = reader.GetInt32(reader.GetOrdinal("EstablishedYear"));
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNumber"))) entity.LicenseNumber = reader.GetString(reader.GetOrdinal("LicenseNumber"));
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationDescription"))) entity.OrganizationDescription = reader.GetString(reader.GetOrdinal("OrganizationDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasPartyOrganization"))) entity.HasPartyOrganization = reader.GetBoolean(reader.GetOrdinal("HasPartyOrganization"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTheCommunistYouthLeague"))) entity.HasTheCommunistYouthLeague = reader.GetBoolean(reader.GetOrdinal("HasTheCommunistYouthLeague"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTradeUnion"))) entity.HasTradeUnion = reader.GetBoolean(reader.GetOrdinal("HasTradeUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasWomanUnion"))) entity.HasWomanUnion = reader.GetBoolean(reader.GetOrdinal("HasWomanUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasInlandMarket"))) entity.HasInlandMarket = reader.GetBoolean(reader.GetOrdinal("HasInlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasOutlandMarket"))) entity.HasOutlandMarket = reader.GetBoolean(reader.GetOrdinal("HasOutlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("MarketDescription"))) entity.MarketDescription = reader.GetString(reader.GetOrdinal("MarketDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("ProductDescription"))) entity.ProductDescription = reader.GetString(reader.GetOrdinal("ProductDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
                collection.Add(entity);
            }
            reader.Close();
            return collection;
        }
        //---------------------------------------------------------------------------------------------
        public static IList<Cooperative> SelectCollectionBy_ChiefAccountantID(int chiefAccountantID)
        {
            List<Cooperative> collection = new List<Cooperative>();
            SqlDataReader reader = (SqlDataReader)SelectReaderBy_ChiefAccountantID(chiefAccountantID);
            while (reader.Read())
            {
                Cooperative entity = new Cooperative();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("AreaID"))) entity.AreaID = reader.GetInt32(reader.GetOrdinal("AreaID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CareerID"))) entity.CareerID = reader.GetInt32(reader.GetOrdinal("CareerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("TypeID"))) entity.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChairmanID"))) entity.ChairmanID = reader.GetInt32(reader.GetOrdinal("ChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChiefAccountantID"))) entity.ChiefAccountantID = reader.GetInt32(reader.GetOrdinal("ChiefAccountantID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ControllerID"))) entity.ControllerID = reader.GetInt32(reader.GetOrdinal("ControllerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ViceChairmanID"))) entity.ViceChairmanID = reader.GetInt32(reader.GetOrdinal("ViceChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) entity.Address = reader.GetString(reader.GetOrdinal("Address"));
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) entity.Email = reader.GetString(reader.GetOrdinal("Email"));
                if (!reader.IsDBNull(reader.GetOrdinal("Fax"))) entity.Fax = reader.GetString(reader.GetOrdinal("Fax"));
                if (!reader.IsDBNull(reader.GetOrdinal("Phone"))) entity.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                if (!reader.IsDBNull(reader.GetOrdinal("Website"))) entity.Website = reader.GetString(reader.GetOrdinal("Website"));
                if (!reader.IsDBNull(reader.GetOrdinal("EstablishedYear"))) entity.EstablishedYear = reader.GetInt32(reader.GetOrdinal("EstablishedYear"));
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNumber"))) entity.LicenseNumber = reader.GetString(reader.GetOrdinal("LicenseNumber"));
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationDescription"))) entity.OrganizationDescription = reader.GetString(reader.GetOrdinal("OrganizationDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasPartyOrganization"))) entity.HasPartyOrganization = reader.GetBoolean(reader.GetOrdinal("HasPartyOrganization"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTheCommunistYouthLeague"))) entity.HasTheCommunistYouthLeague = reader.GetBoolean(reader.GetOrdinal("HasTheCommunistYouthLeague"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTradeUnion"))) entity.HasTradeUnion = reader.GetBoolean(reader.GetOrdinal("HasTradeUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasWomanUnion"))) entity.HasWomanUnion = reader.GetBoolean(reader.GetOrdinal("HasWomanUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasInlandMarket"))) entity.HasInlandMarket = reader.GetBoolean(reader.GetOrdinal("HasInlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasOutlandMarket"))) entity.HasOutlandMarket = reader.GetBoolean(reader.GetOrdinal("HasOutlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("MarketDescription"))) entity.MarketDescription = reader.GetString(reader.GetOrdinal("MarketDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("ProductDescription"))) entity.ProductDescription = reader.GetString(reader.GetOrdinal("ProductDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
                collection.Add(entity);
            }
            reader.Close();
            return collection;
        }
        //---------------------------------------------------------------------------------------------
        public static IList<Cooperative> SelectCollectionBy_ControllerID(int controllerID)
        {
            List<Cooperative> collection = new List<Cooperative>();
            SqlDataReader reader = (SqlDataReader)SelectReaderBy_ControllerID(controllerID);
            while (reader.Read())
            {
                Cooperative entity = new Cooperative();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("AreaID"))) entity.AreaID = reader.GetInt32(reader.GetOrdinal("AreaID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CareerID"))) entity.CareerID = reader.GetInt32(reader.GetOrdinal("CareerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("TypeID"))) entity.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChairmanID"))) entity.ChairmanID = reader.GetInt32(reader.GetOrdinal("ChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChiefAccountantID"))) entity.ChiefAccountantID = reader.GetInt32(reader.GetOrdinal("ChiefAccountantID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ControllerID"))) entity.ControllerID = reader.GetInt32(reader.GetOrdinal("ControllerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ViceChairmanID"))) entity.ViceChairmanID = reader.GetInt32(reader.GetOrdinal("ViceChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) entity.Address = reader.GetString(reader.GetOrdinal("Address"));
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) entity.Email = reader.GetString(reader.GetOrdinal("Email"));
                if (!reader.IsDBNull(reader.GetOrdinal("Fax"))) entity.Fax = reader.GetString(reader.GetOrdinal("Fax"));
                if (!reader.IsDBNull(reader.GetOrdinal("Phone"))) entity.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                if (!reader.IsDBNull(reader.GetOrdinal("Website"))) entity.Website = reader.GetString(reader.GetOrdinal("Website"));
                if (!reader.IsDBNull(reader.GetOrdinal("EstablishedYear"))) entity.EstablishedYear = reader.GetInt32(reader.GetOrdinal("EstablishedYear"));
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNumber"))) entity.LicenseNumber = reader.GetString(reader.GetOrdinal("LicenseNumber"));
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationDescription"))) entity.OrganizationDescription = reader.GetString(reader.GetOrdinal("OrganizationDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasPartyOrganization"))) entity.HasPartyOrganization = reader.GetBoolean(reader.GetOrdinal("HasPartyOrganization"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTheCommunistYouthLeague"))) entity.HasTheCommunistYouthLeague = reader.GetBoolean(reader.GetOrdinal("HasTheCommunistYouthLeague"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTradeUnion"))) entity.HasTradeUnion = reader.GetBoolean(reader.GetOrdinal("HasTradeUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasWomanUnion"))) entity.HasWomanUnion = reader.GetBoolean(reader.GetOrdinal("HasWomanUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasInlandMarket"))) entity.HasInlandMarket = reader.GetBoolean(reader.GetOrdinal("HasInlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasOutlandMarket"))) entity.HasOutlandMarket = reader.GetBoolean(reader.GetOrdinal("HasOutlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("MarketDescription"))) entity.MarketDescription = reader.GetString(reader.GetOrdinal("MarketDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("ProductDescription"))) entity.ProductDescription = reader.GetString(reader.GetOrdinal("ProductDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
                collection.Add(entity);
            }
            reader.Close();
            return collection;
        }
        //---------------------------------------------------------------------------------------------
        public static IList<Cooperative> SelectCollectionBy_ViceChairmanID(int viceChairmanID)
        {
            List<Cooperative> collection = new List<Cooperative>();
            SqlDataReader reader = (SqlDataReader)SelectReaderBy_ViceChairmanID(viceChairmanID);
            while (reader.Read())
            {
                Cooperative entity = new Cooperative();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("AreaID"))) entity.AreaID = reader.GetInt32(reader.GetOrdinal("AreaID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CareerID"))) entity.CareerID = reader.GetInt32(reader.GetOrdinal("CareerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("TypeID"))) entity.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChairmanID"))) entity.ChairmanID = reader.GetInt32(reader.GetOrdinal("ChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChiefAccountantID"))) entity.ChiefAccountantID = reader.GetInt32(reader.GetOrdinal("ChiefAccountantID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ControllerID"))) entity.ControllerID = reader.GetInt32(reader.GetOrdinal("ControllerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ViceChairmanID"))) entity.ViceChairmanID = reader.GetInt32(reader.GetOrdinal("ViceChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) entity.Address = reader.GetString(reader.GetOrdinal("Address"));
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) entity.Email = reader.GetString(reader.GetOrdinal("Email"));
                if (!reader.IsDBNull(reader.GetOrdinal("Fax"))) entity.Fax = reader.GetString(reader.GetOrdinal("Fax"));
                if (!reader.IsDBNull(reader.GetOrdinal("Phone"))) entity.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                if (!reader.IsDBNull(reader.GetOrdinal("Website"))) entity.Website = reader.GetString(reader.GetOrdinal("Website"));
                if (!reader.IsDBNull(reader.GetOrdinal("EstablishedYear"))) entity.EstablishedYear = reader.GetInt32(reader.GetOrdinal("EstablishedYear"));
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNumber"))) entity.LicenseNumber = reader.GetString(reader.GetOrdinal("LicenseNumber"));
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationDescription"))) entity.OrganizationDescription = reader.GetString(reader.GetOrdinal("OrganizationDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasPartyOrganization"))) entity.HasPartyOrganization = reader.GetBoolean(reader.GetOrdinal("HasPartyOrganization"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTheCommunistYouthLeague"))) entity.HasTheCommunistYouthLeague = reader.GetBoolean(reader.GetOrdinal("HasTheCommunistYouthLeague"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTradeUnion"))) entity.HasTradeUnion = reader.GetBoolean(reader.GetOrdinal("HasTradeUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasWomanUnion"))) entity.HasWomanUnion = reader.GetBoolean(reader.GetOrdinal("HasWomanUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasInlandMarket"))) entity.HasInlandMarket = reader.GetBoolean(reader.GetOrdinal("HasInlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasOutlandMarket"))) entity.HasOutlandMarket = reader.GetBoolean(reader.GetOrdinal("HasOutlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("MarketDescription"))) entity.MarketDescription = reader.GetString(reader.GetOrdinal("MarketDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("ProductDescription"))) entity.ProductDescription = reader.GetString(reader.GetOrdinal("ProductDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
                collection.Add(entity);
            }
            reader.Close();
            return collection;
        }
        //---------------------------------------------------------------------------------------------
        public static IList<Cooperative> SelectCollectionBy_TypeID(int typeID)
        {
            List<Cooperative> collection = new List<Cooperative>();
            SqlDataReader reader = (SqlDataReader)SelectReaderBy_TypeID(typeID);
            while (reader.Read())
            {
                Cooperative entity = new Cooperative();
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt32(reader.GetOrdinal("ID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ModuleID"))) entity.ModuleID = reader.GetGuid(reader.GetOrdinal("ModuleID"));
                if (!reader.IsDBNull(reader.GetOrdinal("AreaID"))) entity.AreaID = reader.GetInt32(reader.GetOrdinal("AreaID"));
                if (!reader.IsDBNull(reader.GetOrdinal("CareerID"))) entity.CareerID = reader.GetInt32(reader.GetOrdinal("CareerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("TypeID"))) entity.TypeID = reader.GetInt32(reader.GetOrdinal("TypeID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) entity.Title = reader.GetString(reader.GetOrdinal("Title"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChairmanID"))) entity.ChairmanID = reader.GetInt32(reader.GetOrdinal("ChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ChiefAccountantID"))) entity.ChiefAccountantID = reader.GetInt32(reader.GetOrdinal("ChiefAccountantID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ControllerID"))) entity.ControllerID = reader.GetInt32(reader.GetOrdinal("ControllerID"));
                if (!reader.IsDBNull(reader.GetOrdinal("ViceChairmanID"))) entity.ViceChairmanID = reader.GetInt32(reader.GetOrdinal("ViceChairmanID"));
                if (!reader.IsDBNull(reader.GetOrdinal("Address"))) entity.Address = reader.GetString(reader.GetOrdinal("Address"));
                if (!reader.IsDBNull(reader.GetOrdinal("Email"))) entity.Email = reader.GetString(reader.GetOrdinal("Email"));
                if (!reader.IsDBNull(reader.GetOrdinal("Fax"))) entity.Fax = reader.GetString(reader.GetOrdinal("Fax"));
                if (!reader.IsDBNull(reader.GetOrdinal("Phone"))) entity.Phone = reader.GetString(reader.GetOrdinal("Phone"));
                if (!reader.IsDBNull(reader.GetOrdinal("Website"))) entity.Website = reader.GetString(reader.GetOrdinal("Website"));
                if (!reader.IsDBNull(reader.GetOrdinal("EstablishedYear"))) entity.EstablishedYear = reader.GetInt32(reader.GetOrdinal("EstablishedYear"));
                if (!reader.IsDBNull(reader.GetOrdinal("LicenseNumber"))) entity.LicenseNumber = reader.GetString(reader.GetOrdinal("LicenseNumber"));
                if (!reader.IsDBNull(reader.GetOrdinal("OrganizationDescription"))) entity.OrganizationDescription = reader.GetString(reader.GetOrdinal("OrganizationDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasPartyOrganization"))) entity.HasPartyOrganization = reader.GetBoolean(reader.GetOrdinal("HasPartyOrganization"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTheCommunistYouthLeague"))) entity.HasTheCommunistYouthLeague = reader.GetBoolean(reader.GetOrdinal("HasTheCommunistYouthLeague"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasTradeUnion"))) entity.HasTradeUnion = reader.GetBoolean(reader.GetOrdinal("HasTradeUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasWomanUnion"))) entity.HasWomanUnion = reader.GetBoolean(reader.GetOrdinal("HasWomanUnion"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasInlandMarket"))) entity.HasInlandMarket = reader.GetBoolean(reader.GetOrdinal("HasInlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("HasOutlandMarket"))) entity.HasOutlandMarket = reader.GetBoolean(reader.GetOrdinal("HasOutlandMarket"));
                if (!reader.IsDBNull(reader.GetOrdinal("MarketDescription"))) entity.MarketDescription = reader.GetString(reader.GetOrdinal("MarketDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("ProductDescription"))) entity.ProductDescription = reader.GetString(reader.GetOrdinal("ProductDescription"));
                if (!reader.IsDBNull(reader.GetOrdinal("Description"))) entity.Description = reader.GetString(reader.GetOrdinal("Description"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedDate"))) entity.CreatedDate = reader.GetDateTime(reader.GetOrdinal("CreatedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy"))) entity.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedDate"))) entity.ApprovedDate = reader.GetDateTime(reader.GetOrdinal("ApprovedDate"));
                if (!reader.IsDBNull(reader.GetOrdinal("ApprovedBy"))) entity.ApprovedBy = reader.GetString(reader.GetOrdinal("ApprovedBy"));
                collection.Add(entity);
            }
            reader.Close();
            return collection;
        }
        //---------------------------------------------------------------------------------------------

        public static DataSet SelectBy_AreaID(int areaID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectBy_AreaID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@AreaID", SqlDbType.Int, areaID);

            return db.ExecuteDataSet(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static DataSet SelectBy_CareerID(int careerID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectBy_CareerID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@CareerID", SqlDbType.Int, careerID);

            return db.ExecuteDataSet(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static DataSet SelectBy_ChairmanID(int chairmanID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectBy_ChairmanID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ChairmanID", SqlDbType.Int, chairmanID);

            return db.ExecuteDataSet(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static DataSet SelectBy_ChiefAccountantID(int chiefAccountantID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectBy_ChiefAccountantID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ChiefAccountantID", SqlDbType.Int, chiefAccountantID);

            return db.ExecuteDataSet(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static DataSet SelectBy_ControllerID(int controllerID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectBy_ControllerID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ControllerID", SqlDbType.Int, controllerID);

            return db.ExecuteDataSet(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static DataSet SelectBy_ViceChairmanID(int viceChairmanID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectBy_ViceChairmanID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ViceChairmanID", SqlDbType.Int, viceChairmanID);

            return db.ExecuteDataSet(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static DataSet SelectBy_TypeID(int typeID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectBy_TypeID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@TypeID", SqlDbType.Int, typeID);

            return db.ExecuteDataSet(dbCommand);
        }
        //---------------------------------------------------------------------------------------------

        public static DataSet SelectAll(Guid moduleID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectAll]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            return db.ExecuteDataSet(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static DataSet SelectDynamic(string whereCondition, string orderByExpression)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectDynamic]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);

            return db.ExecuteDataSet(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static IDataReader SelectReaderAll(Guid moduleID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectAll]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            return db.ExecuteReader(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static IDataReader SelectReaderDynamic(string whereCondition, string orderByExpression)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_SelectDynamic]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);

            return db.ExecuteReader(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        // Select by foreign key return collection		
        public static IDataReader SelectReaderBy_AreaID(int areaID)
        {
            const string spName = "p_COOPERATIVE_Cooperative_SelectBy_AreaID";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@AreaID", SqlDbType.Int, areaID);

            return db.ExecuteReader(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static IDataReader SelectReaderBy_CareerID(int careerID)
        {
            const string spName = "p_COOPERATIVE_Cooperative_SelectBy_CareerID";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@CareerID", SqlDbType.Int, careerID);

            return db.ExecuteReader(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static IDataReader SelectReaderBy_ChairmanID(int chairmanID)
        {
            const string spName = "p_COOPERATIVE_Cooperative_SelectBy_ChairmanID";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ChairmanID", SqlDbType.Int, chairmanID);

            return db.ExecuteReader(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static IDataReader SelectReaderBy_ChiefAccountantID(int chiefAccountantID)
        {
            const string spName = "p_COOPERATIVE_Cooperative_SelectBy_ChiefAccountantID";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ChiefAccountantID", SqlDbType.Int, chiefAccountantID);

            return db.ExecuteReader(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static IDataReader SelectReaderBy_ControllerID(int controllerID)
        {
            const string spName = "p_COOPERATIVE_Cooperative_SelectBy_ControllerID";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ControllerID", SqlDbType.Int, controllerID);

            return db.ExecuteReader(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static IDataReader SelectReaderBy_ViceChairmanID(int viceChairmanID)
        {
            const string spName = "p_COOPERATIVE_Cooperative_SelectBy_ViceChairmanID";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ViceChairmanID", SqlDbType.Int, viceChairmanID);

            return db.ExecuteReader(dbCommand);
        }
        //---------------------------------------------------------------------------------------------
        public static IDataReader SelectReaderBy_TypeID(int typeID)
        {
            const string spName = "p_COOPERATIVE_Cooperative_SelectBy_TypeID";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@TypeID", SqlDbType.Int, typeID);

            return db.ExecuteReader(dbCommand);
        }
        //---------------------------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------------------------

        #region Insert methods.

        public static int InsertCooperative(Guid moduleID, int areaID, int careerID, int typeID, string title, int chairmanID, int chiefAccountantID, int controllerID, int viceChairmanID, string address, string email, string fax, string phone, string website, int establishedYear, string licenseNumber, string organizationDescription, bool hasPartyOrganization, bool hasTheCommunistYouthLeague, bool hasTradeUnion, bool hasWomanUnion, bool hasInlandMarket, bool hasOutlandMarket, string marketDescription, string productDescription, string description, DateTime createdDate, string createdBy, DateTime approvedDate, string approvedBy)
        {
            Cooperative entity = new Cooperative();
            entity.ModuleID = moduleID;
            entity.AreaID = areaID;
            entity.CareerID = careerID;
            entity.TypeID = typeID;
            entity.Title = title;
            entity.ChairmanID = chairmanID;
            entity.ChiefAccountantID = chiefAccountantID;
            entity.ControllerID = controllerID;
            entity.ViceChairmanID = viceChairmanID;
            entity.Address = address;
            entity.Email = email;
            entity.Fax = fax;
            entity.Phone = phone;
            entity.Website = website;
            entity.EstablishedYear = establishedYear;
            entity.LicenseNumber = licenseNumber;
            entity.OrganizationDescription = organizationDescription;
            entity.HasPartyOrganization = hasPartyOrganization;
            entity.HasTheCommunistYouthLeague = hasTheCommunistYouthLeague;
            entity.HasTradeUnion = hasTradeUnion;
            entity.HasWomanUnion = hasWomanUnion;
            entity.HasInlandMarket = hasInlandMarket;
            entity.HasOutlandMarket = hasOutlandMarket;
            entity.MarketDescription = marketDescription;
            entity.ProductDescription = productDescription;
            entity.Description = description;
            entity.CreatedDate = createdDate;
            entity.CreatedBy = createdBy;
            entity.ApprovedDate = approvedDate;
            entity.ApprovedBy = approvedBy;
            return entity.Insert();
        }

        public int Insert()
        {
            return this.Insert(null);
        }

        //---------------------------------------------------------------------------------------------

        public int Insert(SqlTransaction transaction)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_Insert]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddOutParameter(dbCommand, "@ID", SqlDbType.Int, 4);
            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, ModuleID);
            db.AddInParameter(dbCommand, "@AreaID", SqlDbType.Int, AreaID);
            db.AddInParameter(dbCommand, "@CareerID", SqlDbType.Int, CareerID);
            db.AddInParameter(dbCommand, "@TypeID", SqlDbType.Int, TypeID);
            db.AddInParameter(dbCommand, "@Title", SqlDbType.NVarChar, Title);
            db.AddInParameter(dbCommand, "@ChairmanID", SqlDbType.Int, ChairmanID);
            db.AddInParameter(dbCommand, "@ChiefAccountantID", SqlDbType.Int, ChiefAccountantID);
            db.AddInParameter(dbCommand, "@ControllerID", SqlDbType.Int, ControllerID);
            db.AddInParameter(dbCommand, "@ViceChairmanID", SqlDbType.Int, ViceChairmanID);
            db.AddInParameter(dbCommand, "@Address", SqlDbType.NVarChar, Address);
            db.AddInParameter(dbCommand, "@Email", SqlDbType.VarChar, Email);
            db.AddInParameter(dbCommand, "@Fax", SqlDbType.VarChar, Fax);
            db.AddInParameter(dbCommand, "@Phone", SqlDbType.VarChar, Phone);
            db.AddInParameter(dbCommand, "@Website", SqlDbType.VarChar, Website);
            db.AddInParameter(dbCommand, "@EstablishedYear", SqlDbType.Int, EstablishedYear);
            db.AddInParameter(dbCommand, "@LicenseNumber", SqlDbType.NVarChar, LicenseNumber);
            db.AddInParameter(dbCommand, "@OrganizationDescription", SqlDbType.NVarChar, OrganizationDescription);
            db.AddInParameter(dbCommand, "@HasPartyOrganization", SqlDbType.Bit, HasPartyOrganization);
            db.AddInParameter(dbCommand, "@HasTheCommunistYouthLeague", SqlDbType.Bit, HasTheCommunistYouthLeague);
            db.AddInParameter(dbCommand, "@HasTradeUnion", SqlDbType.Bit, HasTradeUnion);
            db.AddInParameter(dbCommand, "@HasWomanUnion", SqlDbType.Bit, HasWomanUnion);
            db.AddInParameter(dbCommand, "@HasInlandMarket", SqlDbType.Bit, HasInlandMarket);
            db.AddInParameter(dbCommand, "@HasOutlandMarket", SqlDbType.Bit, HasOutlandMarket);
            db.AddInParameter(dbCommand, "@MarketDescription", SqlDbType.NVarChar, MarketDescription);
            db.AddInParameter(dbCommand, "@ProductDescription", SqlDbType.NVarChar, ProductDescription);
            db.AddInParameter(dbCommand, "@Description", SqlDbType.NVarChar, Description);
            db.AddInParameter(dbCommand, "@CreatedDate", SqlDbType.DateTime, CreatedDate.Year <= 1753 ? DBNull.Value : (object)CreatedDate);
            db.AddInParameter(dbCommand, "@CreatedBy", SqlDbType.VarChar, CreatedBy);
            db.AddInParameter(dbCommand, "@ApprovedDate", SqlDbType.DateTime, ApprovedDate.Year <= 1753 ? DBNull.Value : (object)ApprovedDate);
            db.AddInParameter(dbCommand, "@ApprovedBy", SqlDbType.VarChar, ApprovedBy);

            if (transaction != null)
            {
                db.ExecuteNonQuery(dbCommand, transaction);
                ID = (int)db.GetParameterValue(dbCommand, "@ID");
                return ID;
            }
            else
            {
                db.ExecuteNonQuery(dbCommand);
                ID = (int)db.GetParameterValue(dbCommand, "@ID");
                return ID;
            }
        }

        //---------------------------------------------------------------------------------------------
        public static bool InsertCollection(IList<Cooperative> collection)
        {
            bool ret;
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        bool ret01 = true;
                        foreach (Cooperative item in collection)
                        {
                            if (item.Insert(transaction) <= 0)
                            {
                                ret01 = false;
                                break;
                            }
                        }
                        if (ret01)
                        {
                            transaction.Commit();
                            ret = true;
                        }
                        else
                        {
                            transaction.Rollback();
                            ret = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw new Exception("Error at InsertCollection method: " + ex.Message);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
            return ret;
        }

        #endregion

        //---------------------------------------------------------------------------------------------

        #region Insert / Update methods.

        public static int InsertUpdateCooperative(int id, Guid moduleID, int areaID, int careerID, int typeID, string title, int chairmanID, int chiefAccountantID, int controllerID, int viceChairmanID, string address, string email, string fax, string phone, string website, int establishedYear, string licenseNumber, string organizationDescription, bool hasPartyOrganization, bool hasTheCommunistYouthLeague, bool hasTradeUnion, bool hasWomanUnion, bool hasInlandMarket, bool hasOutlandMarket, string marketDescription, string productDescription, string description, DateTime createdDate, string createdBy, DateTime approvedDate, string approvedBy)
        {
            Cooperative entity = new Cooperative();
            entity.ID = id;
            entity.ModuleID = moduleID;
            entity.AreaID = areaID;
            entity.CareerID = careerID;
            entity.TypeID = typeID;
            entity.Title = title;
            entity.ChairmanID = chairmanID;
            entity.ChiefAccountantID = chiefAccountantID;
            entity.ControllerID = controllerID;
            entity.ViceChairmanID = viceChairmanID;
            entity.Address = address;
            entity.Email = email;
            entity.Fax = fax;
            entity.Phone = phone;
            entity.Website = website;
            entity.EstablishedYear = establishedYear;
            entity.LicenseNumber = licenseNumber;
            entity.OrganizationDescription = organizationDescription;
            entity.HasPartyOrganization = hasPartyOrganization;
            entity.HasTheCommunistYouthLeague = hasTheCommunistYouthLeague;
            entity.HasTradeUnion = hasTradeUnion;
            entity.HasWomanUnion = hasWomanUnion;
            entity.HasInlandMarket = hasInlandMarket;
            entity.HasOutlandMarket = hasOutlandMarket;
            entity.MarketDescription = marketDescription;
            entity.ProductDescription = productDescription;
            entity.Description = description;
            entity.CreatedDate = createdDate;
            entity.CreatedBy = createdBy;
            entity.ApprovedDate = approvedDate;
            entity.ApprovedBy = approvedBy;
            return entity.InsertUpdate();
        }

        //---------------------------------------------------------------------------------------------

        public int InsertUpdate()
        {
            return this.InsertUpdate(null);
        }

        //---------------------------------------------------------------------------------------------

        public int InsertUpdate(SqlTransaction transaction)
        {
            const string spName = "p_COOPERATIVE_Cooperative_InsertUpdate";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, ModuleID);
            db.AddInParameter(dbCommand, "@AreaID", SqlDbType.Int, AreaID);
            db.AddInParameter(dbCommand, "@CareerID", SqlDbType.Int, CareerID);
            db.AddInParameter(dbCommand, "@TypeID", SqlDbType.Int, TypeID);
            db.AddInParameter(dbCommand, "@Title", SqlDbType.NVarChar, Title);
            db.AddInParameter(dbCommand, "@ChairmanID", SqlDbType.Int, ChairmanID);
            db.AddInParameter(dbCommand, "@ChiefAccountantID", SqlDbType.Int, ChiefAccountantID);
            db.AddInParameter(dbCommand, "@ControllerID", SqlDbType.Int, ControllerID);
            db.AddInParameter(dbCommand, "@ViceChairmanID", SqlDbType.Int, ViceChairmanID);
            db.AddInParameter(dbCommand, "@Address", SqlDbType.NVarChar, Address);
            db.AddInParameter(dbCommand, "@Email", SqlDbType.VarChar, Email);
            db.AddInParameter(dbCommand, "@Fax", SqlDbType.VarChar, Fax);
            db.AddInParameter(dbCommand, "@Phone", SqlDbType.VarChar, Phone);
            db.AddInParameter(dbCommand, "@Website", SqlDbType.VarChar, Website);
            db.AddInParameter(dbCommand, "@EstablishedYear", SqlDbType.Int, EstablishedYear);
            db.AddInParameter(dbCommand, "@LicenseNumber", SqlDbType.NVarChar, LicenseNumber);
            db.AddInParameter(dbCommand, "@OrganizationDescription", SqlDbType.NVarChar, OrganizationDescription);
            db.AddInParameter(dbCommand, "@HasPartyOrganization", SqlDbType.Bit, HasPartyOrganization);
            db.AddInParameter(dbCommand, "@HasTheCommunistYouthLeague", SqlDbType.Bit, HasTheCommunistYouthLeague);
            db.AddInParameter(dbCommand, "@HasTradeUnion", SqlDbType.Bit, HasTradeUnion);
            db.AddInParameter(dbCommand, "@HasWomanUnion", SqlDbType.Bit, HasWomanUnion);
            db.AddInParameter(dbCommand, "@HasInlandMarket", SqlDbType.Bit, HasInlandMarket);
            db.AddInParameter(dbCommand, "@HasOutlandMarket", SqlDbType.Bit, HasOutlandMarket);
            db.AddInParameter(dbCommand, "@MarketDescription", SqlDbType.NVarChar, MarketDescription);
            db.AddInParameter(dbCommand, "@ProductDescription", SqlDbType.NVarChar, ProductDescription);
            db.AddInParameter(dbCommand, "@Description", SqlDbType.NVarChar, Description);
            db.AddInParameter(dbCommand, "@CreatedDate", SqlDbType.DateTime, CreatedDate.Year == 1753 ? DBNull.Value : (object)CreatedDate);
            db.AddInParameter(dbCommand, "@CreatedBy", SqlDbType.VarChar, CreatedBy);
            db.AddInParameter(dbCommand, "@ApprovedDate", SqlDbType.DateTime, ApprovedDate.Year == 1753 ? DBNull.Value : (object)ApprovedDate);
            db.AddInParameter(dbCommand, "@ApprovedBy", SqlDbType.VarChar, ApprovedBy);

            if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------
        public static bool InsertUpdateCollection(IList<Cooperative> collection)
        {
            bool ret;
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        bool ret01 = true;
                        foreach (Cooperative item in collection)
                        {
                            if (item.InsertUpdate(transaction) <= 0)
                            {
                                ret01 = false;
                                break;
                            }
                        }
                        if (ret01)
                        {
                            transaction.Commit();
                            ret = true;
                        }
                        else
                        {
                            transaction.Rollback();
                            ret = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw new Exception("Error at InsertUpdateCollection method: " + ex.Message);

                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
            return ret;
        }
        #endregion

        //---------------------------------------------------------------------------------------------

        #region Update methods.

        public static int UpdateCooperative(int id, Guid moduleID, int areaID, int careerID, int typeID, string title, int chairmanID, int chiefAccountantID, int controllerID, int viceChairmanID, string address, string email, string fax, string phone, string website, int establishedYear, string licenseNumber, string organizationDescription, bool hasPartyOrganization, bool hasTheCommunistYouthLeague, bool hasTradeUnion, bool hasWomanUnion, bool hasInlandMarket, bool hasOutlandMarket, string marketDescription, string productDescription, string description, DateTime createdDate, string createdBy, DateTime approvedDate, string approvedBy)
        {
            Cooperative entity = new Cooperative();
            entity.ID = id;
            entity.ModuleID = moduleID;
            entity.AreaID = areaID;
            entity.CareerID = careerID;
            entity.TypeID = typeID;
            entity.Title = title;
            entity.ChairmanID = chairmanID;
            entity.ChiefAccountantID = chiefAccountantID;
            entity.ControllerID = controllerID;
            entity.ViceChairmanID = viceChairmanID;
            entity.Address = address;
            entity.Email = email;
            entity.Fax = fax;
            entity.Phone = phone;
            entity.Website = website;
            entity.EstablishedYear = establishedYear;
            entity.LicenseNumber = licenseNumber;
            entity.OrganizationDescription = organizationDescription;
            entity.HasPartyOrganization = hasPartyOrganization;
            entity.HasTheCommunistYouthLeague = hasTheCommunistYouthLeague;
            entity.HasTradeUnion = hasTradeUnion;
            entity.HasWomanUnion = hasWomanUnion;
            entity.HasInlandMarket = hasInlandMarket;
            entity.HasOutlandMarket = hasOutlandMarket;
            entity.MarketDescription = marketDescription;
            entity.ProductDescription = productDescription;
            entity.Description = description;
            entity.CreatedDate = createdDate;
            entity.CreatedBy = createdBy;
            entity.ApprovedDate = approvedDate;
            entity.ApprovedBy = approvedBy;
            return entity.Update();
        }

        //---------------------------------------------------------------------------------------------

        public int Update()
        {
            return this.Update(null);
        }

        //---------------------------------------------------------------------------------------------

        public int Update(SqlTransaction transaction)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_Update]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);
            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, ModuleID);
            db.AddInParameter(dbCommand, "@AreaID", SqlDbType.Int, AreaID);
            db.AddInParameter(dbCommand, "@CareerID", SqlDbType.Int, CareerID);
            db.AddInParameter(dbCommand, "@TypeID", SqlDbType.Int, TypeID);
            db.AddInParameter(dbCommand, "@Title", SqlDbType.NVarChar, Title);
            db.AddInParameter(dbCommand, "@ChairmanID", SqlDbType.Int, ChairmanID);
            db.AddInParameter(dbCommand, "@ChiefAccountantID", SqlDbType.Int, ChiefAccountantID);
            db.AddInParameter(dbCommand, "@ControllerID", SqlDbType.Int, ControllerID);
            db.AddInParameter(dbCommand, "@ViceChairmanID", SqlDbType.Int, ViceChairmanID);
            db.AddInParameter(dbCommand, "@Address", SqlDbType.NVarChar, Address);
            db.AddInParameter(dbCommand, "@Email", SqlDbType.VarChar, Email);
            db.AddInParameter(dbCommand, "@Fax", SqlDbType.VarChar, Fax);
            db.AddInParameter(dbCommand, "@Phone", SqlDbType.VarChar, Phone);
            db.AddInParameter(dbCommand, "@Website", SqlDbType.VarChar, Website);
            db.AddInParameter(dbCommand, "@EstablishedYear", SqlDbType.Int, EstablishedYear);
            db.AddInParameter(dbCommand, "@LicenseNumber", SqlDbType.NVarChar, LicenseNumber);
            db.AddInParameter(dbCommand, "@OrganizationDescription", SqlDbType.NVarChar, OrganizationDescription);
            db.AddInParameter(dbCommand, "@HasPartyOrganization", SqlDbType.Bit, HasPartyOrganization);
            db.AddInParameter(dbCommand, "@HasTheCommunistYouthLeague", SqlDbType.Bit, HasTheCommunistYouthLeague);
            db.AddInParameter(dbCommand, "@HasTradeUnion", SqlDbType.Bit, HasTradeUnion);
            db.AddInParameter(dbCommand, "@HasWomanUnion", SqlDbType.Bit, HasWomanUnion);
            db.AddInParameter(dbCommand, "@HasInlandMarket", SqlDbType.Bit, HasInlandMarket);
            db.AddInParameter(dbCommand, "@HasOutlandMarket", SqlDbType.Bit, HasOutlandMarket);
            db.AddInParameter(dbCommand, "@MarketDescription", SqlDbType.NVarChar, MarketDescription);
            db.AddInParameter(dbCommand, "@ProductDescription", SqlDbType.NVarChar, ProductDescription);
            db.AddInParameter(dbCommand, "@Description", SqlDbType.NVarChar, Description);
            db.AddInParameter(dbCommand, "@CreatedDate", SqlDbType.DateTime, CreatedDate.Year == 1753 ? DBNull.Value : (object)CreatedDate);
            db.AddInParameter(dbCommand, "@CreatedBy", SqlDbType.VarChar, CreatedBy);
            db.AddInParameter(dbCommand, "@ApprovedDate", SqlDbType.DateTime, ApprovedDate.Year == 1753 ? DBNull.Value : (object)ApprovedDate);
            db.AddInParameter(dbCommand, "@ApprovedBy", SqlDbType.VarChar, ApprovedBy);

            if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------
        public static bool UpdateCollection(IList<Cooperative> collection)
        {
            bool ret;
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        bool ret01 = true;
                        foreach (Cooperative item in collection)
                        {
                            if (item.Update(transaction) <= 0)
                            {
                                ret01 = false;
                                break;
                            }
                        }
                        if (ret01)
                        {
                            transaction.Commit();
                            ret = true;
                        }
                        else
                        {
                            transaction.Rollback();
                            ret = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw new Exception("Error at UpdateCollection method: " + ex.Message);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
            return ret;
        }

        #endregion

        //---------------------------------------------------------------------------------------------

        #region Delete methods.

        public static int DeleteCooperative(int id)
        {
            Cooperative entity = new Cooperative();
            entity.ID = id;

            return entity.Delete();
        }

        public int Delete()
        {
            return this.Delete(null);
        }

        //---------------------------------------------------------------------------------------------

        public int Delete(SqlTransaction transaction)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_Delete]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, ID);

            if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static int DeleteBy_AreaID(int areaID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_DeleteBy_AreaID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@AreaID", SqlDbType.Int, areaID);

            return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static int DeleteBy_CareerID(int careerID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_DeleteBy_CareerID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@CareerID", SqlDbType.Int, careerID);

            return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static int DeleteBy_ChairmanID(int chairmanID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_DeleteBy_ChairmanID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ChairmanID", SqlDbType.Int, chairmanID);

            return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static int DeleteBy_ChiefAccountantID(int chiefAccountantID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_DeleteBy_ChiefAccountantID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ChiefAccountantID", SqlDbType.Int, chiefAccountantID);

            return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static int DeleteBy_ControllerID(int controllerID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_DeleteBy_ControllerID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ControllerID", SqlDbType.Int, controllerID);

            return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static int DeleteBy_ViceChairmanID(int viceChairmanID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_DeleteBy_ViceChairmanID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ViceChairmanID", SqlDbType.Int, viceChairmanID);

            return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static int DeleteBy_TypeID(int typeID)
        {
            const string spName = "[dbo].[p_COOPERATIVE_Cooperative_DeleteBy_TypeID]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@TypeID", SqlDbType.Int, typeID);

            return db.ExecuteNonQuery(dbCommand);
        }

        //---------------------------------------------------------------------------------------------

        public static bool DeleteCollection(IList<Cooperative> collection)
        {
            bool ret;
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
                {
                    try
                    {
                        bool ret01 = true;
                        foreach (Cooperative item in collection)
                        {
                            if (item.Delete(transaction) <= 0)
                            {
                                ret01 = false;
                                break;
                            }
                        }
                        if (ret01)
                        {
                            transaction.Commit();
                            ret = true;
                        }
                        else
                        {
                            transaction.Rollback();
                            ret = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw new Exception("Error at DeleteCollection method: " + ex.Message);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
            return ret;
        }
        #endregion
    }
}